package cn.edu.cxcyzx.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.edu.cxcyzx.entity.Task;
import cn.edu.cxcyzx.entity.TaskMembers;
import cn.edu.cxcyzx.service.TaskMembersService;
import cn.edu.cxcyzx.supervisor.DaoFit;
@Service("TaskMembersService")
public class TaskMembersServiceImpl implements TaskMembersService {
	
	@Resource
	public DaoFit daoFit;
	
	//任务分配
	@Override
	public void inserMembers(String taskId,String[] stuId) {
		// TODO Auto-generated method stub
		if(stuId.length>0){
			String groupId=daoFit.getGroupDao().getGroupBy_projectId(daoFit.getTaskDao().getTaskBy_taskId(taskId).getProjectId()).getGroupId();
			List<TaskMembers> list=new ArrayList<>(stuId.length);//创建初始化指定大小的集合
			for (String id : stuId) {
				list.add(new TaskMembers(taskId, id, groupId));
				daoFit.getMembersDao().updateStatus(groupId, id);
			}
			daoFit.getTaskMembersDao().insertMembers(list);
			daoFit.getTaskDao().update_taskStatus(taskId, 2);
		}
	}

}
